package com.melodyframe.common.context;

public class ContextLocal {
	private static ThreadLocal<Context>	localContext	= new ThreadLocal<Context>();

	public static Context getContext() {
		Context context = localContext.get();
		if (null == context) {
			return reset();
		}
		return context;
	}

	public static Context reset() {
		Context context = new CommonContext();
		localContext.set(context);
		return context;
	}

	public static void put(String scope, ScopeContext context) {
		getContext().addScope(scope, context);
	}

	public static void put(String key, Object value) {
		getContext().put(key, value);
	}

	public static void put(String key, Object value, String scope) {
		getContext().put(key, value, scope);
	}

	public static Object get(String key) {
		return getContext().get(key);
	}

	public static Object get(String key, String scope) {
		return getContext().get(key, scope);
	}
}
